﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Watch_Default : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            DataTable tbl = new DataTable("Tbl");
            Ko2.DB.MySql mysql = new Ko2.DB.MySql();
            Exception err = mysql.GetShopNames(ref tbl);
            if (err == null)
            {
                oShop.DataSource = tbl;
                oShop.DataTextField = "ShopName";
                oShop.DataValueField = "NetBiosName";
                oShop.DataBind();
            }

            for (int i = 1; i <= 36; i++)
                oCamNum.Items.Add(i.ToString());
            oCamNum.DataBind();

        }
    }

    protected void oShop_SelectedIndexChanged(object sender, EventArgs e)
    {
        InvalidateFrameSrc();
    }

    protected void oCamNum_SelectedIndexChanged(object sender, EventArgs e)
    {
        InvalidateFrameSrc();
    }

    private void InvalidateFrameSrc()
    {
        // http://cam0002-1.korablik.local/view/viewer_index.shtml
        string strValue = oShop.SelectedValue;
        if (!String.IsNullOrEmpty(strValue) && strValue.Length >= 2)
        {
            strValue = strValue.Substring(1);
            string strCamNum = (oCamNum.SelectedIndex + 1).ToString();
            string strUrl =
@"http://cam" + strValue + "-" + strCamNum
+ @".korablik.local/view/viewer_index.shtml";
            oIFrame.Attributes["src"] = strUrl;
        }
    }
    
}

